﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">

    <title>Preclinic - Medical & Hospital - Bootstrap 4 Admin Template</title>
    <link rel="stylesheet" type="text/css" href="../static/assets/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="../static/assets/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="../static/assets/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="../static/assets/css/style.css">
    <!--[if lt IE 9]>
    <script src="../static/assets/js/html5shiv.min.js"></script>
    <script src="../static/assets/js/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="main-wrapper">
    <div class="header">
        <div class="header-left">
            <a href="home" class="logo">
                <img src="../static/assets/img/logo.png" width="35" height="35" alt=""> <span>门诊</span>
            </a>
        </div>
        <a id="toggle_btn" href="javascript:void(0);"><i class="fa fa-bars"></i></a>
        <a id="mobile_btn" class="mobile_btn float-left" href="#sidebar"><i class="fa fa-bars"></i></a>
        <ul class="nav user-menu float-right">
            <li class="nav-item dropdown d-none d-sm-block">
                <a href="#" class="dropdown-toggle nav-link" data-toggle="dropdown"><i class="fa fa-bell-o"></i> <span
                        class="badge badge-pill bg-danger float-right">  </span></a>
                <div class="dropdown-menu notifications">
                    <div class="topnav-dropdown-header">
                        <span>Notifications</span>
                    </div>
                    <div class="drop-scroll">
                        <ul class="notification-list">
                            <li class="notification-message">
                                <a href="activities.html">
                                    <div class="media">
											<span class="avatar">
												<img alt="John Doe" src="../static/assets/img/user.jpg" class="img-fluid">
											</span>
                                        <div class="media-body">
                                            <p class="noti-details"><span class="noti-title">John Doe</span> added new
                                                task <span class="noti-title">Patient appointment booking</span></p>
                                            <p class="noti-time"><span class="notification-time">4 mins ago</span></p>
                                        </div>
                                    </div>
                                </a>
                            </li>
                            <li class="notification-message">
                                <a href="activities.html">
                                    <div class="media">
                                        <span class="avatar">V</span>
                                        <div class="media-body">
                                            <p class="noti-details"><span class="noti-title">Tarah Shropshire</span>
                                                changed the task name <span class="noti-title">Appointment booking with payment gateway</span>
                                            </p>
                                            <p class="noti-time"><span class="notification-time">6 mins ago</span></p>
                                        </div>
                                    </div>
                                </a>
                            </li>
                        </ul>
                    </div>
                    <div class="topnav-dropdown-footer">
                        <a href="activities.html">View all Notifications</a>
                    </div>
                </div>
            </li>
            <li class="nav-item dropdown d-none d-sm-block">
                <a href="javascript:void(0);" id="open_msg_box" class="hasnotifications nav-link"><i
                        class="fa fa-comment-o"></i> <span class="badge badge-pill bg-danger float-right">  </span></a>
            </li>
            <li class="nav-item dropdown has-arrow">
                <a href="#" class="dropdown-toggle nav-link user-link" data-toggle="dropdown">
                        <span class="user-img">
							<img class="rounded-circle" src="../static/assets/img/user.jpg" width="24" alt="Admin">
							<span class="status online"></span>
						</span>
                    <span>用户</span>
                </a>
                <div class="dropdown-menu">
                    <a class="dropdown-item" href="#">设置</a>
                    <a class="dropdown-item" href="/loginout">退出登录</a>
                </div>
            </li>
        </ul>
        <div class="dropdown mobile-user-menu float-right">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i
                    class="fa fa-ellipsis-v"></i></a>
            <div class="dropdown-menu dropdown-menu-right">
                <a class="dropdown-item" href="profile.html">My Profile</a>
                <a class="dropdown-item" href="edit-profile.html">Edit Profile</a>
                <a class="dropdown-item" href="settings.html">Settings</a>
                <a class="dropdown-item" href="login.html">Logout</a>
            </div>
        </div>
    </div>
    <div class="sidebar" id="sidebar">

        <div class="sidebar-inner slimscroll">
            <div id="sidebar-menu" class="sidebar-menu">
                <ul>
                    <!--                    <li>-->
                    <!--                        <a href="appointments"><i class="fa fa-calendar"></i> <span>预约信息</span></a>-->
                    <!--                    </li>-->
                    <li>
                        <a href="patients"><i class="fa fa-user"></i> <span> 就诊排号 </span></span></a>
                    </li>
                    <li>
                        <a href="patientInfo"><i class="fa fa-wheelchair"></i> <span>诊断信息</span></a>
                    </li>
                    <li>
                        <a href="#"><i class="fa fa-edit"></i> <span> 申请单</span> <span class="menu-arrow"></span></a>
                        <ul style="display: none;">
                            <li><a href="drugApplyShow">药品申请</a></li>
                        </ul>
                    </li>
                    <li>
                        <a href="javascript:;" id="chatBtn"><i class="fa fa-comments"></i> <span>聊天</span></a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <div class="page-wrapper">
        <div class="content">
            <div class="row col-md-12">
                <div class="row col-md-6"></div>
                <div class="col-md-3">
                    <br>
                    <h4 class="page-title"><strong>药品申请表</strong></h4>
                </div>
            </div>
            <div class="row">

                <div class="col-md-2"></div>

                <div class="col-md-8">
                    <div class="card-box">
                        <h4 class="card-title"><strong></strong></h4>
                        <br>
<!--                        <h4 class="card-title">Personal Information</h4>-->
                        <form action="" method="">
                            <div class="row">
                                <div class="col-md-12">
<!--                                    就诊id-->
                                    <input type="hidden" name="medicalId" id="medicalId">
                                    <div class="form-group row">
                                        <label class="col-md-2 col-form-label card-title"><strong>患者姓名:</strong></label>
                                        <div class="col-md-5">
                                            <input type="text" id="patientName" class="form-control" name="patientName" disabled>
                                        </div>
                                    </div>
                                    <h4 class="card-title"><strong>药品列表</strong></h4>
                                    <div class="table-responsive">
                                        <table class="table table-striped custom-table">
                                            <thead>
                                            <tr>
                                                <th>药品名</th>
                                                <th>单价</th>
                                                <th>数量</th>
                                                <th>总价</th>
                                            </tr>
                                            </thead>
                                            <tbody id="drug-show">
<!--                                                <tr>-->
<!--                                                    <td>感康</td>-->
<!--                                                    <td>10</td>-->
<!--                                                    <td>2</td>-->
<!--                                                    <td>20</td>-->
<!--                                                </tr>-->
                                            </tbody>
                                        </table>
                                        <!-- Button trigger modal -->
                                        <button type="button" id="ad" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
                                            添加药品
                                        </button>
                                        <!-- Modal -->
                                        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                            <div class="modal-dialog" role="document">
                                                <div class="modal-content">
<!--                                                    <form action="">-->
                                                    <div class="modal-header">
<!--                                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>-->
                                                        <h4 class="modal-title" id="myModalLabel"><strong>药品新增</strong></h4>
                                                    </div>
                                                    <div class="modal-body">
                                                        <input type="hidden" name="drugId" id="drugId">
                                                        <div class="form-group row">
                                                            <label class="col-md-3 col-form-label">药品名称</label>
                                                            <div class="col-md-9">
                                                                <select class="select" id="drugName">
                                                                    <option></option>
                                                                </select>
<!--                                                                <input type="text" class="form-control" name="drugName" id="drugName">-->
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">
                                                            <label class="col-md-3 col-form-label">药品单价</label>
                                                            <div class="col-md-9">
                                                                <input type="text" disabled="disabled" class="form-control" name="price" id="price">
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">
                                                            <label class="col-md-3 col-form-label">药品数量</label>
                                                            <div class="col-md-9">
                                                                <input type="number" min="1" class="form-control" name="number" id="number" required>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                                        <button type="submit" id="addDrug" class="btn btn-primary" >添加</button>
                                                    </div>
<!--                                                    </form>-->
                                                </div>
                                            </div>
                                        </div>

                                    </div>


                                </div>
<!--                                <div class="col-md-6">-->
<!--                                </div>-->
                            </div>

                            <div class="text-right">
                                <button type="submit" class="btn btn-primary" id="add-drug-apply">提交申请</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <div class="notification-box">
            <div class="msg-sidebar notifications msg-noti">
                <div class="topnav-dropdown-header">
                    <span>Messages</span>
                </div>
                <div class="drop-scroll msg-list-scroll" id="msg_list">
                    <ul class="list-box">
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">R</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author">Richard Miles </span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item new-message">
                                    <div class="list-left">
                                        <span class="avatar">J</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author">John Doe</span>
                                        <span class="message-time">1 Aug</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">T</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author"> Tarah Shropshire </span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">M</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author">Mike Litorus</span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">C</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author"> Catherine Manseau </span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">D</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author"> Domenic Houston </span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">B</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author"> Buster Wigton </span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">R</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author"> Rolland Webber </span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">C</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author"> Claire Mapes </span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">M</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author">Melita Faucher</span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">J</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author">Jeffery Lalor</span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">L</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author">Loren Gatlin</span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="chat.html">
                                <div class="list-item">
                                    <div class="list-left">
                                        <span class="avatar">T</span>
                                    </div>
                                    <div class="list-body">
                                        <span class="message-author">Tarah Shropshire</span>
                                        <span class="message-time">12:28 AM</span>
                                        <div class="clearfix"></div>
                                        <span class="message-content">Lorem ipsum dolor sit amet, consectetur adipiscing</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                    </ul>
                </div>
                <div class="topnav-dropdown-footer">
                    <a href="chat.html">See all messages</a>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="sidebar-overlay" data-reff=""></div>
<script src="../static/assets/js/jquery-3.2.1.min.js"></script>
<script src="../static/assets/js/popper.min.js"></script>
<script src="../static/assets/js/bootstrap.min.js"></script>
<script src="../static/assets/js/jquery.slimscroll.js"></script>
<script src="../static/assets/js/select2.min.js"></script>
<script src="../static/assets/js/app.js"></script>
<script>

    //获取诊断表基本信息
    var getPatientInfo = function(){
        $.ajax({
            url:"drugApply",
            type:"get",
            dataType:"json",
            success:function (data) {
                if (data.length != 0){
                    console.log(data[0]);
                    $("#medicalId").val(data[0].medicalId);
                    $("#patientName").val(data[0].patientName);
                }else{
                    $("#medicalId").val("");
                    $("#patientName").val("  暂无需要开药的患者 ").css("background","yellow");
                    //按钮设置为不可点击
                    $("button").attr("disabled",true);
                    $("input").attr("disabled",true);
                }
            }
        });
    };

    getPatientInfo();

    var drugInfos = [];
    //需要提交的数组
    var drugApplyList = [];

    //查询药品详情
    $.ajax({
        url:"queryDrugInfo",
        type:"get",
        dataType:"json",
        async:false,
        success:function (data) {
            drugInfos = data;
            if (data.length != 0){
                console.log(data);
                //赋值给全局变量
                drugInfos = data;
                for (var i=0; i<drugInfos.length; i++) {
                    $(".select").append("<option value='"+data[i].drugName+"'>"+ data[i].drugName +"</option>");
                }
            }
        }
    });
    console.log("drugInfos: " + drugInfos[0].drugName);

    // 药品添加
    $("#addDrug").click(function () {
        $(this).attr("data-dismiss","");
        //添加到显示列表
        if ($("#number").val() == "" || $("#drugName").val()=="") {
            console.log("信息未填写完整")
        }else{
            $("#drug-show").append("<tr>\n" +
                // " <td>"+$("#drugName option:selected").text() +"</td>\n" +
                " <td>"+$("#drugName").val() +"</td>\n" +
                "<td>"+ $("#price").val() +"</td>\n" +
                "<td>"+ $("#number").val() +"</td>\n" +
                "<td>"+$("#price").val()*$("#number").val()+"</td>\n" +
                "</tr>");
            // $("#drugName option:selected").attr("selected",false);
            drugApplyList.push({
                medicalId: $("#medicalId").val(),
                drugId:$("#drugId").val(),
                drugApplyCount:$("#number").val(),
                totalPrice:$("#price").val()*$("#number").val()
            });
            $("#number").val("");
            $(this).attr("data-dismiss","modal");
        }
    });

    //设置药品单价
    $(".select").change(function(){
        if (drugInfos.length != 0){
            for (var i=0; i<drugInfos.length; i++){
                if ($(this).val() == drugInfos[i].drugName) {
                    $("#price").val(drugInfos[i].drugPrice);
                    $("#drugId").val(drugInfos[i].drugId);
                }
            }
        }
    });

    //申请提交事件
    $("#add-drug-apply").click(function () {
        console.log("drugApplyList" + drugApplyList);
        $.ajax({
            url:"addDrugApply",
            type:"post",
            // traditional:true,
            contentType : 'application/json;charset=utf-8',
            async:true,
            data:JSON.stringify(drugApplyList),
            // data:{drugApplyList: drugApplyList},
            // dataType:"json",
            success:function (req) {
                console.log("上传成功!!!" + req);
                getPatientInfo();
                //提交的数组设置为空
                drugApplyList = [];
                //清空显示列表所有元素
                $("#drug-show").empty();
            },
            error:function () {
                console.log("上传失败!!!");
            }
        });

    })

</script>
</body>

</html>